import {createRouter, createWebHistory} from 'vue-router'
import {ref} from "vue";


const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/login',
            name: 'login',
            component: () => import('@/views/login/login.vue'),
            meta: {title: '登录'}
        },
        {
            path: '/',
            name: 'layout',
            component: () => import('@/views/layout/layout.vue'),
            children: [
                {
                    path: '/',
                    name: 'home',
                    component: () => import('@/views/home/home.vue'),
                    meta: {title: '首页'}
                },
                {
                    path: '/address',
                    name: 'address',
                    component: () => import('@/views/home/address.vue'),
                    meta: {title: '收件地址'}
                },
                {
                    path: '/cars',
                    name: 'cars',
                    component: () => import('@/views/home/cars.vue'),
                    meta: {title: '购物车'}
                },
                {
                    path: '/pay/:orderId',
                    name: 'pay',
                    component: () => import('@/views/home/pay.vue'),
                    meta: {title: '支付'}
                },
                {
                    path: '/payBack',
                    name: 'payBack',
                    component: () => import('@/views/home/payBack.vue'),
                    meta: {title: '支付回执'}
                },
                {
                    path: '/detail/:id',
                    name: 'detail',
                    component: () => import('@/views/home/details.vue'),
                    meta: {title: '商品详情'},
                },
                {
                    path: '/headDetail/:id',
                    name: 'headDetail',
                    component: () => import('@/views/home/headDetails.vue'),
                    meta: {title: '分类详情'},
                },
                {
                    path: '/user',
                    name: 'user',
                    component: () => import('@/views/home/person/user.vue'),
                    meta: {title: '个人信息'},
                    children: [
                        {
                            path: '/user/myOrder',
                            name: 'myOrder',
                            component: () => import('@/views/home/person/myOrder.vue'),
                            meta: {title: '我的订单'}
                        },
                        {
                            path: '/user/personalCenter',
                            name: 'personalCenter',
                            component: () => import('@/views/home/person/personalCenter.vue'),
                            meta: {title: '个人中心'}
                        }
                    ]
                }
            ]

        }
    ]
})
const originalPush = createRouter.prototype.push;
createRouter.prototype.push = function push(location: any) {
    return originalPush.call(this, location).catch((err: any) => {
        return err
    })
}

const headData = ref([])


export default router